﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BranchOfSansar.Sansar.Transfer;

namespace BranchOfSansar.Register.Trans
{
    public partial class frmTransDelete : BranchOfSansar.Register.Trans.frmTransBase
    {
        vw_Transaction Trans = null;
        public frmTransDelete(vw_Transaction trans)
        {        
            InitializeComponent();
            this.Trans = trans;
            txtTransNo.Text = trans.TransNo.ToString();
            txtAmount.Text = trans.TxnAmount.ToString("#,##0");
            txtDesc.Text = trans.TxnDesc;
            txtDidDate.Text = trans.TxnDate.ToString("yyyy.MM.dd");
            txtDate.EditValue = Globals.SystemDate;
            SetContractNo(trans.ContractNo??0);
            cmbTransCategory.Enabled = false;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Transaction r_trans = new Transaction()
            {
                JrNo = Trans.JrNo,
                TxnFirstBalance = 0,
                TxnPrice = 0,
                Quantity = 0,
                TxnType = 9999,
                UserNo = Globals.UserId,
                TxnDate = Globals.SystemDate,
                PostDate = DateTime.Now,
                TxnDesc = txtReason.Text,
                ContractNo = Trans.ContractNo,
                PerTransNo = Trans.TransNo,
                TxnCategory = ((BranchOfSansar.Sansar.Enquiry.ComboItem)cmbTransCategory.SelectedItem).StrValue,
                Status=0
            };
            using (TransferClient tc = new TransferClient(Globals.Token))
            {
                var res=tc.Reject(Trans.TransNo, r_trans);
                
                if (res.Code != 0)
                    Globals.Warr(res.Message);
                else
                {
                    Globals.Info(res.Message);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
        }

        private void frmTransDelete_Load(object sender, EventArgs e)
        {

        }


    }
}
